#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.apiimpl;

import ${package}.api.DemoApi;
import ${package}.convert.DemoConverter;
import ${package}.api.dto.DemoDto;
import ${package}.service.DemoService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.common.core.dto.CommonResultDto;
import com.ruoyi.common.core.utils.PageUtils;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.PageResultDto;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

/**
 * demo示例实现
 *
 * @author ruoyi
 * @date 2022-02-15 10:59:29
 */
@RequestMapping("/v1/demo")
@RestController
@DubboService(group = "${symbol_dollar}{dubbo.application.name}",protocol = "${symbol_dollar}{dubbo.protocol.name}",
        version = "${symbol_dollar}{dubbo.service.version}")
public class DemoApiImpl implements DemoApi {
    @Autowired
    private DemoService demoService;

    /**
     * 分页询示例信息
     */
    @RequiresPermissions("ruoyi:demo:list")
    @Override
    public PageResultDto<DemoDto> selectPage(DemoDto demo) {
        IPage page = demoService.page(PageUtils.getPage(),
                DemoConverter.buildWrapper(demo));
        return new PageResultDto(DemoConverter.INSTANCE.
                doList2DtoList(page.getRecords()), page.getTotal());
    }

    /**
     * 查询示例信息列表
     */
    @Override
    @RequiresPermissions("ruoyi:demo:list")
    public CommonResultDto<List<DemoDto>> list(DemoDto demo) {
        return CommonResultDto.success(DemoConverter.INSTANCE.
                doList2DtoList(demoService.list(DemoConverter.buildWrapper(demo))));
    }

    /**
     * 导出示例信息列表
     */
    @RequiresPermissions("ruoyi:demo:export")
    @Log(title = "示例信息", businessType = BusinessType.EXPORT)
    @Override
    public void export(HttpServletResponse response, DemoDto demo) {
        List<DemoDto> list = DemoConverter.INSTANCE.
                doList2DtoList(demoService.list(DemoConverter.buildWrapper(demo)));
        ExcelUtil<DemoDto> util = new ExcelUtil<>(DemoDto.class);
        util.exportExcel(response, list, "示例信息数据");
    }

    /**
     * 获取示例信息详细信息
     */
    @RequiresPermissions("ruoyi:demo:query")
    @Override
    public CommonResultDto<DemoDto> getInfo(@PathVariable("id") Long id) {
        return CommonResultDto.success(DemoConverter.INSTANCE.do2Dto(demoService.getById(id)));
    }

    /**
     * 新增示例信息
     */
    @RequiresPermissions("ruoyi:demo:add")
    @Log(title = "示例信息", businessType = BusinessType.INSERT)
    @Override
    public CommonResultDto<Boolean> add(@RequestBody DemoDto demo) {
        return CommonResultDto.success(demoService.save(DemoConverter.INSTANCE.dto2Do(demo)));
    }

    /**
     * 修改示例信息
     */
    @RequiresPermissions("ruoyi:demo:edit")
    @Log(title = "示例信息", businessType = BusinessType.UPDATE)
    @Override
    public CommonResultDto<Boolean> edit(@RequestBody DemoDto demo) {
        return CommonResultDto.success(demoService.updateById(DemoConverter.INSTANCE.dto2Do(demo)));
    }

    /**
     * 删除示例信息
     */
    @RequiresPermissions("ruoyi:demo:remove")
    @Log(title = "示例信息", businessType = BusinessType.DELETE)
    @Override
    public CommonResultDto<Boolean> remove(@PathVariable Long[] ids) {
        return CommonResultDto.success(demoService.removeByIds(Arrays.asList(ids)));
    }
}
